package com.cz.nongyetongv5.floatview;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.application.InitApplication;

public class FloatWindowBigView extends LinearLayout {

    /**
     * 记录大悬浮窗的宽度
     */
    public static int viewWidth;

    /**
     * 记录大悬浮窗的高度
     */
    public static int viewHeight;

    public FloatWindowBigView(final Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.float_window_big, this);
        View view = findViewById(R.id.big_window_layout);
        viewWidth = view.getLayoutParams().width;
        viewHeight = view.getLayoutParams().height;
        Button btnBackToMain = (Button) findViewById(R.id.btnBackToMain);
        Button back = (Button) findViewById(R.id.back);
        btnBackToMain.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                InitApplication initApplication = (InitApplication) context
                        .getApplicationContext();

                List<Activity> activities = initApplication.getActivities();

                for (int i = 1; i < activities.size(); i++) {

                    activities.get(i).finish();

                }

                // 创建小悬浮窗
                MyWindowManager.removeBigWindow(context);
                MyWindowManager.createSmallWindow(context);

            }
        });

        back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 点击返回的时候，移除大悬浮窗，创建小悬浮窗
                MyWindowManager.removeBigWindow(context);
                MyWindowManager.createSmallWindow(context);
            }
        });
    }
}
